<div id="<%= widget_result_id %>">
  <% if @message %>
      <div class="alert alert-info">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <%= @message %>
      </div>
  <% end %>
</div>
<div>
  <%= form_tag '/session/sign_in', :remote => true, :id => 'login_form' do %>

      <div class="form-group">
        <label for="login">Username or Email address</label>
        <%= text_field_tag "login", nil, :class => "form-control", :placeholder => "Login or email" %>
      </div>

      <div class="form-group">
        <%= password_field_tag "password", nil, :class => "form-control", :placeholder => "**********" %>
      </div>

      <input type="hidden" name="logout_to" value="<%= @logout_to %>"/>
      <input type="hidden" name="login_to" value="<%= @login_to %>"/>

      <p class="text-center">
        <%= submit_tag "Login", :disable_with => "Please wait...", :class => "btn btn-primary submit", :style => '' %>
        <% unless @signup_url.blank? %> | <%= link_to 'Sign Up', @signup_url %>
        <% end %>
        <% unless @reset_password_url.blank? %> | <%= link_to 'Reset Password', @reset_password_url %>
        <% end %>
      </p>

  <% end %>
</div>

<script type="text/javascript">
    jQuery('#login_form').bind('ajax:success', function (e, response) {
        var html = '';

        if (response.success) {
            window.location = response.login_to;
        }
        else {
            html = [
                '<div class="alert alert-danger" >',
                '<button type="button" class="close" data-dismiss="alert">&times;</button>',
                response.errors.reason,
                '</div>'
            ].join('');
        }

        jQuery('#<%=widget_result_id%>').html(html);
    });
</script>




